﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRProject.Code.DAO;
using HRProject.Code.Common;
using HRProject.Code.DTO;
using System.Collections.Generic;

namespace HRProject.Role
{
    public partial class RemoveRole : System.Web.UI.Page
    {
        private Guid roleId = Guid.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            string roleIdStr = Request.Params["id"];
            try
            {
                roleId = new Guid(roleIdStr);
            }
            catch (Exception exp)
            {
                Console.Out.Write(exp.StackTrace);
                roleId = Guid.Empty;
            }
            if (!IsPostBack)
            {
                RoleDAO dao = new RoleDAO();
                BLRole filter = new BLRole();
                filter.Id = roleId;
                filter.Name=string.Empty;
                filter.Department=new BLDepartment();
                filter.Department.Id=Guid.Empty;
                List<BLRole> roles = dao.searchRolesInDepartment(filter);
                if (roles.Count > 0)
                {
                    lblName.Text = roles[0].Name;
                    lblDescription.Text = roles[0].Description;
                }
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (!BLAuthentication.IsRemoveAllowed)
            {
                lblError.Text = ContentProvider.GetMessage("NotAuthorized");
                return;
            }

            RoleDAO dao = new RoleDAO();
            BLRole filter = new BLRole();
            filter.Id = roleId;
            int result = dao.deleteRole(filter);
            if (result > 0)
            {
                Util.CloseFrame(Response);
            }
            else
            {
                //lblError.Text = Resource.AlreadyExistRoleError.Replace("{0}", roleName);
            }
        }
    }
}
